<?php

/**
 * main actions.
 *
 * @package    explications_informatiques
 * @subpackage main
 * @author     Guimezanes Cyrille
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class mainActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
	
		$q = Doctrine_Query::create()
		->from('news n')
		->where('n.online = ?', '1')
		->orderBy('n.idnews desc')
		->limit(10);
		$this->news = $q->execute();
	
		
	$q = Doctrine_Query::create()
	 	->from('revisions c')
		->leftJoin('c.SfGuardUserProfile f')
		->leftJoin('f.User')
		->leftJoin('c.Assoplatform d')
		->leftJoin('d.Articles')
		->orderBy('c.idrevisions desc')
		->limit(10);
	 $this->revisions =  $q->execute();
	
	$q = Doctrine_Query::create()
	->from('articles n')
	->leftJoin('n.Assoplatform c')
	->leftJoin('c.Commentaires')
	->leftJoin('c.Platform')
	->leftJoin('c.Platform_4')
	->leftJoin('n.Tags')
	->where('n.online = ?', '1')
	->orderBy('n.idarticles desc')
	->limit(10);
	
	$this->articles = $q->execute();
	$this->nb_coms = array();
	
	foreach($this->articles as $art)
	{
		$nb = 0;
		foreach($art["Assoplatform"] as $asso)
		{
			$nb += count($asso["Commentaires"]);
		}
		$this->nb_coms[] = $nb;
	}
	
	
	 $q = Doctrine_Query::create()
	->from('lexiqueMot u')
	->leftJoin('u.SfGuardUserProfile p')
	->leftJoin('u.Lexiquedefinition')
	->leftJoin('p.User')
	->where('u.online = ?', '1')
	->orderBy('u.idlexique_mot desc')
	->limit(10);
	
	$this->lexiques = $q->execute();
	
  }
}
